﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace YXShop.Web.admin.stocks
{
    public partial class product_truck : System.Web.UI.Page
    {

        BLL.Stocks.ProductTruck bllProductTurck = new BLL.Stocks.ProductTruck();
        BLL.Stocks.BarCode bllBarCode = new BLL.Stocks.BarCode();
        BLL.Store.StoreCenter bllStoreCenter = new BLL.Store.StoreCenter();
        BLL.Store.Store bllStore = new BLL.Store.Store();
        BLL.Admin.Administrators bllAdmin = new BLL.Admin.Administrators();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string where = "";
                this.lblList.Text = GetList(where);
            }
        }
        #region 绑定
        private string GetList(string where)
        {
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            ChangeHope.DataBase.DataByPage dataPage = bllProductTurck.GetList(where);
            table.AddHeadCol("", "<input id=\"chall\" type=\"checkbox\" onclick=\"SelectAll(chall)\" />全选");
            table.AddHeadCol("", "条码");
            table.AddHeadCol("", "仓库类型");
            table.AddHeadCol("", "仓库名称");
            table.AddHeadCol("", "操作类型");
            table.AddHeadCol("", "时间");
            table.AddHeadCol("", "操作人员");
            table.AddRow();
            if (dataPage.DataReader != null)
            {
                int curpage = ChangeHope.WebPage.PageRequest.GetInt("pageindex");
                if (curpage < 0)
                {
                    curpage = 1;
                }
                int count = 0;
                YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();

                while (dataPage.DataReader.Read())
                {
                    count++;
                    string No = (15 * (curpage - 1) + count).ToString();
                    Model.Stocks.ProductTruck productTruckModel = bllProductTurck.GetModelById(int.Parse(dataPage.DataReader["id"].ToString()));
                    table.AddCol("<input id=\"cbTm\"  type=\"checkbox\" value=\"" + dataPage.DataReader["id"].ToString() + "\" />");
                    Model.Stocks.BarCode barCodeModel = bllBarCode.GetModelById(int.Parse(dataPage.DataReader["barcodeid"].ToString()));
                    int productid = barCodeModel.Productid;
                    table.AddCol(barCodeModel.Barcode);
                    string stocktype = "";
                    if (productTruckModel.StoreType == Model.Stocks.StockTypeEnum.CenterStock)
                    {
                        stocktype = "中央仓库";
                    }
                    if (productTruckModel.StoreType == Model.Stocks.StockTypeEnum.AreaStock)
                    {
                        stocktype = "区域中心";
                    }
                    if (productTruckModel.StoreType == Model.Stocks.StockTypeEnum.ShopStock)
                    {
                        stocktype = "门店仓库";
                    }
                    table.AddCol(stocktype);
                    string stockName = "";
                    if ((int)productTruckModel.StoreType == 0)//中央仓库
                    {
                        stockName = "中央仓库";
                    }
                    if ((int)productTruckModel.StoreType == 1)//区域中心
                    {

                        stockName = bllStoreCenter.GetModelById(productTruckModel.StoreID).StoreCentername;
                    }
                    if ((int)productTruckModel.StoreType == 2)//门店
                    {
                        stockName = bllStore.GetModelById(productTruckModel.StoreID).Storename;
                    }
                    table.AddCol(stockName);
                    string state = "";
                    if ((int)(productTruckModel.OperationType) == 0)
                    {
                        state = "订购";
                    }
                    if ((int)(productTruckModel.OperationType) == 1)
                    {
                        state = "入库";
                    }
                    if ((int)(productTruckModel.OperationType) == 2)
                    {
                        state = "出库";
                    }
                    if ((int)(productTruckModel.OperationType) == 3)
                    {
                        state = "售出";
                    }
                    if ((int)(productTruckModel.OperationType) == 4)
                    {
                        state = "退货";
                    }
                    if ((int)(productTruckModel.OperationType) == 5)
                    {
                        state = "删除";
                    }
                    table.AddCol(state);
                    int adminid=int.Parse(dataPage.DataReader["adminid"].ToString());
                    Model.Admin.Administrators adminModel=bllAdmin.GetModel(adminid);
                    string adminname = "";
                    if (adminModel != null)
                    {
                        adminname = adminModel.Name;
                    }
                    table.AddCol(dataPage.DataReader["operationTime"].ToString());
                    table.AddCol(adminname);
                    table.AddRow();
  
                }
                
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            return view;
        }
        #endregion

        protected void linkQuery_Click(object sender, EventArgs e)
        {
            string barcode = txtBarcode.Text.Trim();
            int state = -1;
            state = int.Parse(this.DropDownList1.SelectedItem.Value);
            //Model.Stocks.ProductStateEnum state = (Model.Stocks.ProductStateEnum)int.Parse(this.DropDownList1.SelectedItem.Value);
            int barcodeid=-1;
            if(barcode!="")
            {
                Model.Stocks.BarCode barcodeModel = bllBarCode.GetModelByBarCode(barcode);
                if (barcodeModel != null)
                {
                    barcodeid = bllBarCode.GetModelByBarCode(barcode).ID;
                }
            }
            string where = "";
            if (barcodeid > 0)
            {
                where = " and barcodeid =" + barcodeid;
            }
            if (state > -1)
            {
                where += " and operationType="+state;
            }
            this.lblList.Text=GetList(where);


        }
    }
}